function check(needReturn){
    var tel = document.getElementById("email");
    var pwd = document.getElementById("pwd");
    var telValue =tel.value;
    var pwdValue = pwd.value;
    var telReg = /^1[3-9][0-9]{9}$/;
    var telRight = false;
    var pwdRight = false;

    if(telValue.length==0){
        error1.innerHTML = "此项必填";
        telRight = false;
    }else if(!telReg.test(telValue)){
        error1.innerHTML = "手机号无效";
        telRight = false;
    }else{
        error1.innerHTML = "";
        telRight = true;
    }

    if(pwdValue.length==0){
        error2.innerHTML = "此项必填";
        pwdRight = false;
    }else if(pwdValue.length<6){
        error2.innerHTML = "密码长度必须6位以上";
        pwdRight = false;
    }else{
        error2.innerHTML = "";
        pwdRight = true;
    }

    if(needReturn) {
        return telRight && pwdRight;
    }
}
window.onload=function(){
    if(localStorage.getItem("tel")){
        email.value=localStorage.getItem("tel")
    }
};
email.onblur=function(){
    var Reg=/^1[3-9][0-9]{9}$/;
    if(Reg.test(email.value)){
        localStorage.setItem("tel",email.value);

    }
};


btn.onclick = function(){
    if(!check(true)){
        return;
    }
    $.ajax({
        type:"POST",
        url:baseurl+"/bijiuser/login",
        contentType:"application/json;charset=utf-8",
        data:JSON.stringify({
            "pwd": pwd.value,
            "tel": email.value
        }),
        success:function (data) {
            if(data){
                tip.innerHTML="登录成功";
                location = "index.html";
            }else{
                tip.innerHTML="登录失败";
            }
        }
    })

};

email.onkeyup = check;
pwd.onkeyup = check;